<?php
if( !defined('IN_INDEX') )
{
	printError("ACCESS DENIED", "This page is hidden.");
	exit;
}
if(!checkSession())
{
			function redirect($url)
			{
			?>
				<script type="text/javascript">
					{
					window.location = "<?=$url?>";
					}
				</script>
			<?php 
			}
			redirect("index.php?action=login");
	exit;
}

$weight_metric = array('kg', 'lbs');
$date_format = $USER->getDateFormat();
$date_format_long = $USER->getDateFormatLong();
$timezone = $USER->getTimezone();
$lang = $USER->getLang();
if(isset($_POST['settings_submit']))
{
	$settings_checked = 0;
	if(isset($_POST['weight_metric']) && !empty($_POST['weight_metric']))
	{
		$USER->setWeight_metric($_POST['weight_metric']);
		$settings_checked++;
	}
	if(isset($_POST['date_format']) && !empty($_POST['date_format']))
	{
		$USER->setDateFormat($_POST['date_format']);
		$settings_checked++;
	}
	if(isset($_POST['date_format_long']) && !empty($_POST['date_format_long']))
	{
		$USER->setDateFormatLong($_POST['date_format_long']);
		$settings_checked++;
	}
	if(isset($_POST['timezone_list']) && $_POST['timezone_list'] != '-')
	{
		$USER->setTimezone($_POST['timezone_list']);
		$settings_checked++;
	}
	if(isset($_POST['lang']) && $_POST['lang'] != '-')
	{
		$USER->setLang($_POST['lang']);
		$settings_checked++;
	}
	
	if(isset($_POST['pm_per_page']) && !empty($_POST['pm_per_page']))
	{
		$USER->setPmPerPage($_POST['pm_per_page']);
		$settings_checked++;
	}
	
	if(isset($_POST['user_get_email_notify'])){
		$USER->setUserGetEmailNotify(intval($_POST['user_get_email_notify']));
		$settings_checked++;
	}else{
		$USER->setUserGetEmailNotify(0);
		$settings_checked++;
	}
	if(isset($_POST['user_get_email_notify_pm'])){
		$USER->setUserGetEmailNotify_PM(intval($_POST['user_get_email_notify_pm']));
		$settings_checked++;
	}else{
		$USER->setUserGetEmailNotify_PM(0);
		$settings_checked++;
	}
	
	if($settings_checked > 0)
	{
		$USER->update();
		echo"<br /><br /><br /><br /><br /><br /><br /><br /><br />
		<center><meta http-equiv=\"refresh\"content=\"3;url=index.php?action=profile&sub=edit_general\">";
		echo "<h2>" . ucfirst(translate('settings_saved')) . "</h2>\n";
		echo "<br/>" . translate('redirectedin'). " <a href=\"index.php?action=profile&sub=edit_general\">" . translate('clickhere') . "</a>.</center>
		<div class='fixed'>
					</div>
				</div>
				</div>
			<div class='fixed'>
			</div>
			<div id='footer'>
			<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
				<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
                </div>";
		exit;
	}
}
$array_posts = array(1, 3, 5, 7, 10, 15, 20, 30, 50, 100);
?>
<script type="text/javascript">
	function setDefaultDateFormat()
	{
		var element = document.getElementById('date_format');
		element.value = 'd.m.Y';
	}
	function setDefaultDateFormatLong()
	{
		var element = document.getElementById('date_format_long');
		element.value = 'd.m.Y @ H:i:s';
	}
</script>

<div id='postpath'>
	<a title="<?php echo translate('gotofrontpage'); ?>" href="index.php"><?php echo translate('home'); ?></a>
    &gt; <a href="index.php?action=blogs" title='<?php echo translate('showallblogs'); ?>'><?php echo translate('blog'); ?></a> 
    &gt; <a href="index.php?action=profile&id=<?php echo $USER->getId(); ?>"><?php echo ucf($USER->getFirstname()) . " " . ucf($USER->getLastname()); ?></a>
	&gt; <a href="index.php?action=profile&sub=edit" title='<?php echo translate('edit'); ?>'><?php echo translate('edit'); ?></a> 
	&gt; <a href="index.php?action=profile&sub=edit_general" title='<?php echo translate('generalsettings'); ?>'><?php echo translate('generalsettings'); ?></a> 
</div>
<br />


<h2><?php echo translate('generalsettings'); ?></h2>
<br />
<?php echo translate('yourtime'); ?>: <?php echo $time_new; ?> <?php echo "(GMT " . $TIME_ZONES[$tzid]['gmt'] . ") "; ?><br />
<?php echo translate('servertime'); ?>: <?php echo $time_org; ?>
<br /><br />
<form action="index.php?action=profile&sub=edit_general" method="post" id="general_settings" name="general_settings">
    
	<table border="1" width="100%" cellspacing="0" cellpadding="3">
        				<tr>
                	<td>
                		<img src="img/lan_edit.png" /> <b><?php echo translate('language'); ?></b>
                		<div class="set_subtext"><?php echo translate('chooseyour displaylanguage'); ?></div>
                	</td>
                	<td>
                		<select name="lang">
                		<?php 
                		foreach($LANG_LIST as $key => $val)
                		{
                			if($val['iso'] == $lang)
                			{
                				echo "<option value=\"" . $val['iso'] . "\" selected=\"selected\">" . $val['name'] . " - " . translate($val['local_name']) . "</option>\n";
                			}
                			else
                			{
                				echo "<option value=\"" . $val['iso'] . "\">" . $val['name'] . " - " . translate($val['local_name']) . "</option>\n";
                			}
                		}
		                ?>
		              </select>
                	</td>
                </tr>
                
               <tr>
                	<td>
                		<img src="img/tz_edit.png" /> <b>Timezone</b> <a href="http://en.wikipedia.org/wiki/Time_zone" title="<?php echo translate('clicktoopeninanewpage'); ?>" target="_blank">[?]</a>
                		<div class="set_subtext"><?php echo translate('chooseyourtimezone'); ?></div>
                	</td>
                	<td>
                		<?php 
                		$preselected_timezone = $timezone;
                		include('inc/timezone_select.php');
		                ?>
                	</td>
                </tr>
                
                <tr>
                        <td width="37%" valign="top"><img src="img/wm_edit.png" /> <b><?php echo translate('weightmetric'); ?></b>
                        <div class="set_subtext"><?php echo translate('chooseyourmetric forviewingandposting'); ?></div>
                        </td>
                    
                        <td width="63%">
                        <select name="weight_metric">
                        	<?php
                        	foreach($weight_metric as $key => $val)
                        	{
                        		if($val == $USER->getWeight_metric())
                        		{
                        			echo "<option value=\"" . $val . "\" selected=\"selected\">" . ucf(translate($val)) . "</option>\n";
                        		}
                        		else
                        		{
                        			echo "<option value=\"" . $val . "\">" . ucf(translate($val)) . "</option>\n";
                        		}
                        	}
                        	?>
                        </select>
                        </td>
                </tr>
                <tr>
                	<td>
                		<img src="img/df_edit.png" /> <b><?php echo translate('dateformat'); ?></b> <a href="http://php.net/manual/en/function.date.php" title="<?php echo translate('clicktoopeninanewpage'); ?>" target="_blank">[?]</a>
                		<div class="set_subtext"><?php echo translate('Choosehowyouwanttoshowthedate'); ?></div>
                	</td>
                	<td>
                		<input type="text" name="date_format" id="date_format" value="<?php echo $date_format; ?>" />
                		<span><a href="javascript:void(0);" title="<?php echo translate('set_default'); ?>" onclick="setDefaultDateFormat(); return false;">[<?php echo translate('default'); ?>]</a>
                	</td>
                </tr>
                <tr>
                	<td>
                		<img src="img/df_edit.png" /> <b><?php echo translate('dateformatlong'); ?></b> <a href="http://php.net/manual/en/function.date.php" title="<?php echo translate('clicktoopeninanewpage'); ?>" target="_blank">[?]</a>
                		<div class="set_subtext"><?php echo translate('choosehowyouwanttoshowthedatewithtimes'); ?></div>
                	</td>
                	<td>
                		<input type="text" name="date_format_long" id="date_format_long" value="<?php echo $date_format_long; ?>" />
                		<span><a href="javascript:void(0);" title="<?php echo translate('set_default'); ?>" onclick="setDefaultDateFormatLong(); return false;">[<?php echo translate('default'); ?>]</a>
                	</td>
                </tr>
	</table> 
    <br />
    <h2><?php echo ucf(translate('messages')); ?> </h2>
    <br />
    <table border="1" width="100%" cellspacing="0" cellpadding="4">    
    	<tr>
			<td width="37%" valign="top">
				<img src="img/pm_unread.png" /> <b><?php echo translate('nrpmperpage'); ?></b>
				<div class="set_subtext"><?php echo translate('nrpmperpage_subtext'); ?></div>
			</td>
			<td>
                <select name="pm_per_page">
				<?php
					foreach($array_posts as $key => $val)
					{
						if($val == $USER->getPmPerPage())
						{
							echo "<option value=\"" . $val . "\" selected=\"selected\">" . $val . "</option>\n";
						}
						else
						{
							echo "<option value=\"" . $val . "\">" . $val . "</option>\n";
						}
					}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td width="37%" valign="top">
				<img src="img/pm_unread.png" /> <b><?php echo translate('get_email_notify'); ?></b>
				<div class="set_subtext"><?php echo translate('get_email_notify_subtext'); ?></div>
			</td>
			<td>
               
				<?php
					
					$selected = ($USER->getUserEmailNotify() == 1) ? ' checked="checked"':'';
				?>
				 <input type="checkbox" name="user_get_email_notify" id="user_get_email_notify" value="1" <?php echo $selected; ?> />
			</td>
		</tr>
		<tr>
			<td width="37%" valign="top">
				<img src="img/pm_unread.png" /> <b><?php echo translate('user_get_email_notify_pm'); ?></b>
				<div class="set_subtext"><?php echo translate('user_get_email_notify_pm_subtext'); ?></div>
			</td>
			<td>
               
				<?php
					
					$selected2 = ($USER->getUserEmailNotify_PM() == 1) ? ' checked="checked"':'';
				?>
				 <input type="checkbox" name="user_get_email_notify_pm" id="user_get_email_notify_pm" value="1" <?php echo $selected2; ?> />
			</td>
		</tr>
		
  </table>
  <br />
  <?php echo translate('Clickonthequestionmarktogethelpopensinanewpage'); ?>
  <br /><br />
  <input style="font-weight:bold;" type="submit" value=" <?php echo translate('save'); ?> " name="settings_submit" />   
</form>